import {get, post} from "@/api/base/http";
import {ApiUri} from "@/api/base/ApiPath";
import {AppParams} from "@/utils/appParams";
// @ts-ignore
import store from '../vue2-flow/src/store'
// @ts-ignore
import Utils from "@/vue2-flow/src/utils/Common";
import {useFlowStore} from "@/store/modules/flow/flowStore";

let ApiPath = new ApiUri();

//let FlowStore: any

export class System {

    constructor() {
        // FlowStore = useFlowStore()
    }

    static GetConfig = () => {
        return get(ApiPath.System.CONFIG);
    }

    static OpenFile = (FileParam: object) => {
        return post(ApiPath.System.OPEN_FILE, FileParam);
    }

    static GetGlobalParams = () => {
        const FlowStore = useFlowStore()
        return get(ApiPath.GlobalParam.ROOT).then(res => {
            if (res.IsSuccess && !Utils.IsEmpty(res.Data)) {
                for (let re of res.Data) {
                    re.dataSource = AppParams.DATA_SOURCE_TYPE.GLOBAL_PARAM
                }
                FlowStore.SetGlobalParams(res.Data);
                return res;
            }
        });
    }

    /**
     * 打开窗口
     * @param Uri
     * @constructor
     */
    static OpenForm(Uri: string) {
        return get(ApiPath.System.OPEN_FORM, {Uri: Uri});
    }

    /**
     * 打开日志窗口
     * @constructor
     */
    static OpenLoggerForm() {
        const URL = 'http://localhost:5173/#/logger';
        // window.open(
        //     URL,        // 新窗口加载的 URL（本地页面/远程地址）
        //     "name",       // 窗口名称（可用于复用窗口）
        // );
        window.open(URL, "_blank", "width=800,height=600,left=100,top=100,toolbar=no,location=yes");
        //return this.OpenForm('/#/logger');
    }
}
